package dpss.replicamanager.gui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

/**
 * Custom cell renderer for the listing table
 * 
 * @author musab.mirza
 * 
 */
class MyCellRenderer implements TableCellRenderer {

	public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer();

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(
				table, value, isSelected, hasFocus, row, column);

		
		// Color of the row should be determined by the if its assigned or not
		if (table.getModel().getValueAt(row, Constants.LISTING_COLUMN_GROUP).toString()
				.equalsIgnoreCase("uninitialized")) {
			renderer.setBackground(Color.cyan);
		} else {
			Integer fails = (Integer) table.getModel().getValueAt(row, Constants.LISTING_COLUMN_FAILS)  ;
			switch (fails) {
			case 0: renderer.setBackground(Color.green); break;
			case 1: renderer.setBackground(Color.decode("#F2B1B1")); break;
			case 2: renderer.setBackground(Color.decode("#F28888")); break;
			case 3: renderer.setBackground(Color.decode("#ED5151")); break;
			default:
				break;
			}
		}
		
		// If fails are there change depending upon failcount
		

		return renderer;
	}
}
